package cn.com.karl.reader;

import org.geometerplus.zlibrary.ui.android.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

public class OnlineStoreActivity extends Activity {
	OnlineStoreActivity context = this;
	
	private WebView mWebView;       
    private Handler mHandler = new Handler();  
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//		setContentView(R.layout.online_store);
//		
//		ImageView image = (ImageView)findViewById(R.id.online_store_image_view);
//		image.setOnClickListener(new View.OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				Intent intent = new Intent(context, BookShelfActivity.class);
//				startActivity(intent);
//				context.finish();
//			}
//		});
		
		setContentView(R.layout.webview);       
        mWebView = (WebView) findViewById(R.id.wv);
        
        //点击链接继续在当前browser中响应
        mWebView.setWebViewClient(new WebViewClient(){       
            public boolean shouldOverrideUrlLoading(WebView view, String url) {       
                view.loadUrl(url);       
                return true;       
            }       
        });   
        WebSettings webSettings = mWebView.getSettings(); 
        
        //设置支持Javascript
        webSettings.setJavaScriptEnabled(true);
        
        //触摸焦点起作用
        mWebView.requestFocus();
        //取消滚动条
        mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        
        mWebView.addJavascriptInterface(new Object() {       
            public void clickOnAndroid() {       
                mHandler.post(new Runnable() {       
                    public void run() {       
                        mWebView.loadUrl("javascript:wave()");       
                    }       
                });       
            }       
        }, "sina");       
        mWebView.loadUrl("http://book.sina.cn/");  
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent(context, BookShelfActivity.class);
			startActivity(intent);
			context.finish();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}
}
